package com.group.product.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.group.commons.entity.Product;
import com.group.commons.service.AdminService;
import com.group.product.service.impl.ProductServiceImpl;
import com.group.commons.util.ResponseInfo;
import com.group.commons.util.ResponseStatus;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author :spj
 * @date:2022/6/6
 * @description:
 */
@RestController
@RequestMapping("/product")
public class ProductController {
    @Resource
    ProductServiceImpl productService;

    @GetMapping("/test")
    public Object test() {
        return null;
    }

    @PostMapping("/product")
    public ResponseInfo<Integer> addProduct(@RequestBody Product product) {
        Integer i = productService.addProduct(product);
        if (i != null) {
            return new ResponseInfo<>(200, "添加成功", null, ResponseStatus.SUCCESS);
        }
        return new ResponseInfo<>(400, "添加失败", null, ResponseStatus.FAILED);
    }
    @PostMapping("/product/{page}/{pages}/{cid}")
    public ResponseInfo<List<Product>> findAllProduct(@PathVariable("page")int page,@PathVariable("pages")int pages,@PathVariable("cid")int id,@RequestBody Product product){
        Page<Product> pagePlus=new Page<>(page,pages);
        List<Product> products = productService.selectAllProduct(pagePlus, id, product);
        if (products != null) {
            return new ResponseInfo<>(200, "查询成功", products, ResponseStatus.SUCCESS);
        }
        return new ResponseInfo<>(400, "查询失败", null, ResponseStatus.FAILED);
    }



}
